<?php
require_once($application_folder."/controllers/navigator.php");
class Comments extends Navigator{

    function __construct(){
        parent::__construct();
        
        /************************************************************
        * CHECK LOGIN
        *************************************************************/
        if(!$this->session->userdata('logged_in')){
            redirect(base_url());
        }
        
        $this->load->model('comments_mod');
        $this->load->helper('date');
    }

    function index(){
        $this->preview();
    }

    function preview($aproved = ""){
        
        /************************************************************
        * GET Comments
        *************************************************************/
        
        switch ($aproved){
            case '':
            $data['comments'] = $this->comments_mod->getAllComments(-1);
            $this->core_cms('comments', $data, 'preview');
            break;
            
            case 'aproved':
            $data['comments'] = $this->comments_mod->getAllComments(1);
            $this->core_cms('comments', $data, 'preview_aproved');
            break;
            
            case 'blocked':
            $data['comments'] = $this->comments_mod->getAllComments(0);
            $this->core_cms('comments', $data, 'preview_blocked');
            break;
        }                                          
    }

    
    
    function commentstatus(){
        
        $this->db->where('id',$_POST['id']);
        $this->db->update('comments', array('aproved' => $_POST['status']));
        echo json_encode(array('action'=> true));
    }

}